using PureMVC.Core;
using PureMVC.Patterns.Proxy;

namespace CounterApp.PureMVC
{
    public class CounterAppModelProxy : Proxy
    {
        public const string NAME = "COUNTER_APP_MODEL";

        // 不可以直接对外暴露 Model 对象
        private CounterAppModel mModel
        {
            get { return Data as CounterAppModel; }
        }

        public CounterAppModelProxy(object data = null) : base(NAME, data)
        {
        }

        public int Count
        {
            get { return mModel.Count; }
        }

        public void IncreaseCount()
        {
            mModel.Count++;
        }

        public void DecreaseCount()
        {
            mModel.Count--;
        }

        public override void OnRegister()
        {
            // 可以写一些 数据 初始化相关的代码 等
        }

        public override void OnRemove()
        {
            Data = null;
        }
    }
}